<?php

class Temp extends CI_Controller {

	function __construct()
        {
                parent::__construct();
                $this->load->config('hell');
                $this->load->helper('data');
                $this->load->helper('date');
                $this->load->helper('url');
                $this->load->library('Parser');
                $this->load->library('calendar');
                $this->load->database('default');
                $this->load->library('BigBlueButton', NULL, 'bbb');
                $this->load->library('Webinar');
                $this->load->model('WebinarDB','wdb');
        }

        function index()
        {
                
                //$this->load->database('default');
                $db = $this->load->database('webdb', true);
              /*  $query = $this->db->query('EXECUTE[AUTH].[dbo].[CHECK_RIGHTS] 41083,757,null');
                print_r($query->row(1));*/
                echo '<title>'.$this->config->item('title').'</title>';
                echo '<script src="'.jquery_url().'" type="text/javascript"></script>';
                echo '<script type="text/javascript">
                        $(document).ready(function(){
                                $("#sbmt").click(function(){
                                        $("#login").val(encodeURIComponent($("#login").val()))
                                        $("#form").submit();
                                        });
                                });
                        </script>';
                echo '<form id="form" action="temp" method="post">
                        <input type="text" name="col" />
                        <input id="login" type="text" name="login" />
                        <input id="sbmt" type="button" value="check" />
                        </form>';
                if(isset($_POST['login'])&&isset($_POST['col'])){

            /*   echo $this->db->query("CREATE TABLE IF NOT EXISTS  `ci_sessions` (
session_id varchar(40) DEFAULT '0' NOT NULL,
ip_address varchar(16) DEFAULT '0' NOT NULL,
user_agent varchar(50) NOT NULL,
last_activity int(10) unsigned DEFAULT 0 NOT NULL,
user_data text DEFAULT '' NOT NULL,
PRIMARY KEY (session_id)
);");*/
                //phpinfo();
                /*echo mssql_connect('webdb.vvsu.ru', 'inet', 'iest');
                echo mssql_query("select * from [Users]..[rgh_users] where login = 'Merkulov_I'");
                echo mssql_close();*/
                //$query = $this->db->query('EXEC [Users].[dbo].[ECheckLoginAndPassword] \'tgear\' ,\'nitro\'');
                //$login = mb_convert_encoding ($login, 'utf8');
                //$login = mb_convert_encoding(urldecode($_POST['login']), 'CP1251');
		$login = $_POST['login'];
                        //echo $login.'<br />';
                $col = $this->input->post('col');
                $query = $db->query("select * from [Users]..[rgh_users] where login = 'Merkulov_I'");
                foreach ($query->result_array() as $row)
                {
                        echo '-----------------------------------<br />';
                    foreach($row as $k => $v){
                            echo $k." ".$v."<br />";
                    }
                        echo '-----------------------------------<br />';
                }
                //$row = $query->row(1);
                //echo $row->status;
                /*$data['welcome'] = '<? $this->load->view("index/welcome_tpl"); ?>';
                /$dt = json_encode($data);
                echo $dt;*/

                }
        }

        function time()
        {
                $period = 'Mon Thu Sun ';
                $this->load->helper('date');
                $sdata = '2011-04-19';
                $edata = '2011-06-30';
                preg_match_all('|\w+\s|', $period, $matches);
                $day = mdate('%d', strtotime($sdata));
                $month = mdate('%m', strtotime($sdata));
                $year = mdate('%Y', strtotime($sdata));
                while(strtotime($edata)>=strtotime($year.'-'.$month.'-'.$day)){
                        foreach ($matches[0] as $key => $val)
                        {
                                if(mdate('%D', strtotime($year.'-'.$month.'-'.$day)) == substr($val,0,3))
                                {
                                        echo mdate('%d', strtotime($year.'-'.$month.'-'.$day)).'<br/>';
                                }
                        }
                        if($day < days_in_month($month, $year)) $day++; else { $day = 1; $month++;}
                }
                while(strtotime($edata)>=strtotime($year.'-'.$month.'-'.$day)){
                        echo mdate('%D', strtotime($year.'-'.$month.'-'.$day)).'<br/>';
                        ($month < 12) ? $month++ : $month=1;
                }
                while(strtotime($edata)>=strtotime($sdata)){
                        echo $sdata.'<br />';
                        $sdata = mdate('%Y-%m-%d', strtotime($sdata)+700000);
                }
        }

        function users($users = '')
        {
                $this->load->model('Check', 'model');
                $data = $this->model->getUsers();
                print_r($data);
        }

        function tpl()
        {
		$this->load->model('check');
                $base['base_url'] = base_url();
                $dt = $base;
                $data = $base;
                echo $this->check->getUserByID('41083');
                $data['header'] = $this->parser->parse("templates/header.html", $base, TRUE);
                $data['account'] = $this->parser->parse("index/login_tpl", $base, TRUE);

                $dt['webinar'] = $this->webinar->now_running('', $this->bbb->url, $this->bbb->salt);
                $data['nowRunning'] = $this->parser->parse("templates/nowRunning.html", $dt, TRUE);
                unset($dt['webinar']);
                
                $data['about'] = $this->parser->parse("templates/feedback.html", $base, TRUE);
                $data['footer'] = $this->parser->parse("templates/footer.html", $base, TRUE);

                $dt['week'] = $this->calendar->week();
                $dt['calendar'] = $this->calendar->bbbmonth(mdate('%m',now()),mdate('%Y',now()));

                $data['calendar'] = $this->parser->parse("templates/calendar.html", $dt, TRUE);
                unset($dt['week']);
                unset($dt['calendar']);

                $data['welcome'] = $dt['welcome'] = $this->parser->parse('bbb/moderator_tpl', $data, true);

                $this->parser->parse("templates/new.html", $data);
        }

        function cap()
        {
                $this->load->helper('captcha');
                $vals = array(
                    //'image' => '<img src="captcha" />',
                    //'time'	=> time(),
                    //'word'	 => 'Random word',
                    'img_path'	 => './captcha/',
                    'img_url'	 => 'http://192.168.10.124/captcha/'
                    //'font_path'	 => './system/fonts/texb.ttf',
                    //'img_width'	 => '150',
                    //'img_height' => '30',
                    //'expiration' => '7200'
                    );

                $cap = create_captcha($vals);
                echo $cap['image'];
                print_r($cap);
        }
}
